package com.dduggs;

import org.junit.Assert;
import org.junit.Test;
import org.springframework.format.number.CurrencyFormatter;

import java.math.BigDecimal;
import java.math.RoundingMode;
import java.text.ParseException;
import java.util.Locale;

/**
 * @author Created by CJS on 2018/4/8
 * @ClassName:
 * @Description:
 */
public class FormatterTest {

    @Test
    public void test1() throws ParseException{
        CurrencyFormatter currencyFormatter=new CurrencyFormatter();
        currencyFormatter.setFractionDigits(2);
        currencyFormatter.setRoundingMode(RoundingMode.CEILING);
        Assert.assertEquals(new BigDecimal("123.13"),currencyFormatter.parse("$123.125", Locale.US));
    }

    @Test
    public void test2() throws ParseException{
        CurrencyFormatter currencyFormatter=new CurrencyFormatter();
        currencyFormatter.setFractionDigits(2);
        currencyFormatter.setRoundingMode(RoundingMode.CEILING);
        Assert.assertEquals("$123.00",currencyFormatter.print(new BigDecimal("123"), Locale.US));
    }

}
